#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;
using db = double;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int a[N],n,f[N],fa[N],ans,siz[N],son[N],tim,dfn[N],R[N],top[N],id[N];
vec G[N];

inline int upd(int x) { return x + (x >> 31 & mod); }

struct BIT {
	int tr[N];
	void clear() { memset(tr,0,sizeof tr); }
	void add(int x,int v) { for(; x <= n; x += x & -x) tr[x] = upd(tr[x] + v - mod); }
	int query(int x) { int res = 0; for(; x; x -= x & -x) res = upd(res + tr[x] - mod); return res; }
} T;

void dfs(int x) {
	siz[x] = 1; son[x] = 0;
	for(auto y : G[x]) dfs(y),siz[x] += siz[y],son[x] = siz[y] > siz[son[x]] ? y : son[x];
}

void dfs1(int x,int anc) {
	top[x] = anc; dfn[x] = ++tim; if(son[x]) dfs1(son[x],anc);
	for(auto y : G[x]) if(y ^ son[x]) dfs1(y,y); R[x] = tim;
}

int queryup(int x) {
	int res = 0;
	while(x) {
		res += upd(T.query(dfn[x]) - T.query(dfn[top[x]] - 1)) - mod; x = fa[top[x]]; res = upd(res);
	}
	return res;
}

int querytr(int x) {
	return upd(T.query(R[x]) - T.query(dfn[x] - 1));
}

void solve() {
	n = in; rep(i, 1, n) G[i].clear();
	rep(i, 2, n) fa[i] = in,G[fa[i]].pb(i);
	rep(i, 1, n) a[i] = in,id[i] = i;
	tim = 0; dfs(1); dfs1(1,1);
	sort(id + 1,id + n + 1,[](int x,int y) { return a[x] < a[y]; });
	T.clear();
	rep(x, 1, n) {
		int i = id[x]; f[i] = 0; f[i] = upd(queryup(i) + querytr(i) - mod); f[i] = upd(f[i] + 1 - mod);
		T.add(dfn[i],f[i]);
	}
	ans = T.query(n); cout << upd(ans - n) << endl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	for(int T = in; T; T--) solve();
}
